package com.sz.app.oss.api.trade;

import com.sz.app.oss.constants.MessagesCodes;
import com.sz.biz.app.web.BaseController;
import com.sz.biz.common.platform.entity.PlatformCompanyBank;
import com.sz.biz.common.platform.entity.PlatformCompanyBankInfo;
import com.sz.biz.common.platform.service.PlatformCompanyBankService;
import com.sz.common.base.dto.ResultDto;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Function: 银行信息 <br>
 * Author: jifeixing <br>
 * Date: 2017-10-10 14:18:00
 */
@RestController
@RequestMapping("${api}/trd/bank")
@Api(description = " ", tags = "047、贸易-平台公司银行帐号信息")
public class PlatformCompanyBankController extends BaseController {

    @Autowired
    private PlatformCompanyBankService platformCompanyBankService;

    /**
     * 新建银行信息
     *
     * @throws Exception
     */
    @ApiOperation(value = "新建银行信息", notes = "新建银行信息")
    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    public ResultDto save(@RequestBody @ApiParam(value = "银行信息", required = true) @Validated PlatformCompanyBankInfo platformCompanyBankInfo) {
        platformCompanyBankService.save(platformCompanyBankInfo);
        return this.getSaveSuccessDto(MessagesCodes.MODULE_TRADE_PLATFORM_BANK);
    }

    /**
     * 编辑银行信息
     *
     * @throws Exception
     */
    @ApiOperation(value = "编辑银行信息", notes = "编辑银行信息")
    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    public ResultDto update(@RequestBody @ApiParam(value = "银行信息", required = true) @Validated PlatformCompanyBankInfo platformCompanyBankInfo) {
        platformCompanyBankService.update(platformCompanyBankInfo);
        return this.getUpdateSuccessDto(MessagesCodes.MODULE_TRADE_PLATFORM_BANK);
    }

    /**
     * 删除银行信息
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除银行信息", notes = "删除银行信息")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "ids", value = "银行信息id数组", required = true, dataType = "array", paramType = "body")})
    @RequestMapping(value = "/delete", method = {RequestMethod.POST})
    public ResultDto batchDeleteByIds(@RequestBody List<Integer> ids) {
        platformCompanyBankService.batchDeleteByIds(ids);
        return getDeleteSuccessDto(MessagesCodes.MODULE_TRADE_PLATFORM_BANK);
    }

    /**
     * 根据id查询银行信息
     */
    @ApiOperation(value = "根据id查询银行信息", notes = "根据id查询银行信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "银行信息id ", required = true, dataType = "Integer", paramType = "path")})
    @RequestMapping(value = "/{id}", method = {RequestMethod.GET})
    public ResultDto getGoodsById(@PathVariable Integer id) {
        PlatformCompanyBank platformCompanyBank = platformCompanyBankService.findById(id);
        ResultDto dto = new ResultDto();
        dto.setData(platformCompanyBank);
        return dto;
    }

    /**
     * 银行信息列表
     */
    @ApiOperation(value = "银行信息列表", notes = "银行信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "platformCompanyId", value = "公司平台id", required = true, dataType = "Integer", paramType = "path")})
    @RequestMapping(value = "/list/{platformCompanyId}", method = {RequestMethod.GET})
    public ResultDto findGoodsList(@PathVariable Integer platformCompanyId) {
        List<PlatformCompanyBank> platformCompanyBanks = platformCompanyBankService.findAll(platformCompanyId);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(platformCompanyBanks);
        return resultDto;
    }

}
